package com.example.system.manager;

import com.example.common.core.constants.CacheConstants;
import com.example.common.redis.RedisService;
import com.example.system.domain.exam.Exam;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @author 23050
 * @version 1.0
 * @description: 往redis中存储
 * @date 2025/3/9 15:22
 */
@Component
public class ExamCacheManager {

    @Resource
    private RedisService redisService;

    //将这个竞赛放到未完赛的list中    并将这个竞赛的信息存到redis中
    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKey(), exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    //删除redis中的 未完赛list中的信息
    //删除redis中存储的发布竞赛的详情
    //删除redis中这个竞赛包含的题目列表的信息
    public void deleteCache(Long examId) {
        redisService.removeForList(getExamListKey(), examId);
        redisService.deleteObject(getDetailKey(examId));
        redisService.deleteObject(getExamQuestionListKey(examId));
    }

    private String getExamListKey() {
        return CacheConstants.EXAM_UNFINISHED_LIST;
    }

    private String getDetailKey(Long examId) {
        return CacheConstants.EXAM_DETAIL + examId;
    }


    private String getExamQuestionListKey(Long examId) {
        return CacheConstants.EXAM_QUESTION_LIST + examId;
    }




}
